package ${classPackageNameMap[table.className+'Controller']};

import java.text.SimpleDateFormat;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.beans.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import ${basePackage}.api.model.${table.className}Vo;
import ${basePackage}.api.service.${table.className}JsfService;

/**
* @author ${author!}
* @since ${timeNow!}
* ${table.remarks!}
*/
@Slf4j
@RestController
@RequestMapping("/${m.toDir(table.modelName)}")
public class ${table.className}Controller {
    @Resource private ${table.className}JsfService ${table.classNameFirstLower}Service;

    /**
     * 根据id查询
     * @param id id
     * @return APIResult<${table.className+'Vo'}>
     */
    @RequestMapping(value = "/queryById")
    public APIResult<${table.className+'Vo'}> queryById(@RequestParam("id") Long id){
        log.info("${table.className}Controller.queryById,通过id查询,id:{}",id);
        try {
            ${table.className+'Vo'} res = ${table.classNameFirstLower}Service.queryById(id);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
    /**
     * 根据条件查询对象
     * @param query 查询条件Vo
     * @return APIResult<${table.className+'Vo'}>
     */
    @RequestMapping(value = "/queryForObject")
    public APIResult<${table.className+'Vo'}> queryForObject(@RequestBody ${table.className}Vo query) {
        log.info("${table.className}Controller.queryForObject,根据条件查询对象,${table.className}Vo:{}",query);
        try {
            ${table.className+'Vo'} res = ${table.classNameFirstLower}Service.queryForObject(query);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
    /**
     * 根据条件查询列表
     * @param query 查询条件Vo
     * @return APIResult${"\l"}List<${table.className+'Vo'}>>
     */
    @RequestMapping(value = "/queryForList")
    public APIResult${"\l"}List<${table.className+'Vo'}>> queryForList(@RequestBody ${table.className}Vo query) {
        log.info("${table.className}Controller.queryForList,查询列表,${table.className}Vo:{}",query);
        try {
            List<${table.className+'Vo'}> res = ${table.classNameFirstLower}Service.queryForList(query);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
    /**
     * 根据条件查询分页
     * @param query 查询条件Voß
     * @return APIResult${"\l"}PageResult<${table.className+'Vo'}>>
     */
    @RequestMapping(value = "/queryPageList")
    public APIResult${"\l"}PageResult<${table.className+'Vo'}>> queryPageList(@RequestBody ${table.className}Vo query){
        log.info("${table.className}Controller.queryPageList,查询列表,${table.className}Vo:{},PageRequest",query);
        try {
            PageResult<${table.className+'Vo'}> res = ${table.classNameFirstLower}Service.queryPageList(query);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
    /**
     * 新增
     * @param entity 要新增的对象
     * @return 影响记录数
     */
    @RequestMapping(value = "/insert")
    public APIResult${"\l"}Long> insert(@RequestBody ${table.className} entity) {
        log.info("${table.className}Controller.insert,新增,${table.className}:{}",entity);
        try {
            Long res = ${table.classNameFirstLower}Service.insert(entity);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
    /**
     * 更新
     * @param entity 要更新的对象
     * @return 影响记录数
     */
    @RequestMapping(value = "/update")
    public APIResult${"\l"}Integer> update(@RequestBody ${table.className} entity) {
        log.info("${table.className}Controller.update,更新,${table.className}:{}",entity);
        try {
            Integer res = ${table.classNameFirstLower}Service.update(entity);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
    /**
     * 根据id删除
     * @param id id
     * @return 影响记录数
     */
    @RequestMapping(value = "/deleteById")
    public APIResult${"\l"}Integer> deleteById(@RequestParam("id") Long id){
        log.info("${table.className}Controller.deleteById,根据id删除,id:{}",id);
        try {
            Integer res = ${table.classNameFirstLower}Service.deleteById(id);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
    /**
     * 新增或修改
     * @param param 要保存的对象
     * @return 影响记录数
     */
    @RequestMapping(value = "/save")
    public APIResult${"\l"}Long> save(@RequestBody ${table.className}Vo param) {
        log.info("${table.className}Controller.save,保存,param:{}",param);
        try {
            Long res = ${table.classNameFirstLower}Service.save(param);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
}